/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Converter;

import dao.EscolaDAO;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import Bean.Escola;
import javax.ejb.EJB;
import javax.faces.convert.FacesConverter;
import javax.inject.Named;
import javax.naming.InitialContext;




/**
 *
 * @author alexandre
 */
@FacesConverter(value = "EscolaConverter")
public class EscolaConverter implements Converter{
   Escola escola = null;
    private EscolaDAO getSession() {
        try {
            return (EscolaDAO) new InitialContext().lookup("java:global/SIAC4/EscolaDAO");
        } catch (Exception ex) {
            throw new IllegalArgumentException(ex);
        }
    }
   
   
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        EscolaDAO instance = getSession();
       
              Integer id = Integer.valueOf(value);
              escola =instance.getEscolaID(id);
              return escola;
      
        
    } 

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        Escola esc = (Escola)value;
        if(esc != null){
            return String.valueOf(esc.getID());
        }
        else{
            return null;
        }
        
    }
    
}
